using System;
using System.Collections.Generic;
using System.ComponentModel;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

using Elephant.Utility;

using Elephant.Framework;
using Elephant.Framework.Services;

namespace Elephant.Utility.Components
{
    public class LookAtCamera : Camera
    {
        Transform transform, target;

        public override void Initialize(bool addDependencies)
        {
            base.Initialize(addDependencies);

            transform = Owner.Find<Transform>();
        }

        public Transform Target
        {
            get
            {
                return target;
            }
            set
            {
                target = value;
            }
        }

        public override Matrix View
        {
            get
            {
                // target.Position is not the absolute position if the target is parented
                return Matrix.CreateLookAt(
                    transform.Position, 
                    target != null ? target.World.Translation : Vector3.Zero,//target.World.Translation, 
                    Vector3.Up);
            }
        }
    }
}
